define([
		'js/_directives/module.js',
		'jquery',
		//,'bootstrapDatepicker'
		
		
    	'js/_directives/bootstrapSwitch.js',
//        ,'js/_directives/simpleDatepicker.js'
        
//        ,'js/_directives/treeView.js'
//        ,'js/_directives/pagInation.js'
//        ,'js/_directives/queryLike.js'
//        ,'js/_directives/selectWithLabel.js'
//        ,'js/_directives/invoiceCategory.js'
//        ,'js/_directives/settleCategory.js'
    	
    	'js/_directives/settleCategoryTileRoot.js',//平台专用（结算方式）
//        ,'js/_directives/taxType.js'
//        ,'js/_directives/attachments.js'
        
        
//        ,'js/_directives/u2frame.js'
//        ,'js/_directives/tdInput.js'
//        ,'js/_directives/rowInation.js'
//        ,'js/_directives/bottomTab.js'
        //制单信息
//        ,'js/_directives/cetInfo.js'
//        ,'js/_directives/gridFilter.js'
//        ,'js/_directives/rangeFilter.js'
//        ,'js/_directives/itemProcess.js'
//        ,'js/_directives/qualityType.js'
//        ,'js/_directives/qualityStatus.js'
//        ,'js/_directives/auditStatus.js'
//        ,'js/_directives/modalSelect.js'
//        ,'js/_directives/settleCategoryModal.js'
//        ,'js/_directives/modalEdit.js'
       
        //以上指令为正式使用中的
//        ,'js/_directives/u2EchartsCommon.js'


        ],function(directives,$){
	
	
	/*
	创建自定义AngularJS 指令
	//创建指令模块 (或者检索现有模块) 
	var m = angular.module("myApp");
	
	// 创建"my-dir"指令 
	myApp.directive("myDir", function() { 
	  return { 
	    restrict: "E",        // 指令是一个元素 (并非属性) 
	    scope: {              // 设置指令对于的scope 
	      name: "@",          // name 值传递 （字符串，单向绑定） 
	      amount: "=",        // amount 引用传递（双向绑定） 
	      save: "&"           // 保存操作 
	    }, 
	    template:             // 替换HTML (使用scope中的变量) 
	      "<div>" + 
	      "  {{name}}: <input ng-model='amount' />" + 
	      "  <button ng-click='save()'>Save</button>" + 
	      "</div>", 
	    replace: true,        // 使用模板替换原始标记 
	    transclude: false,    // 不复制原始HTML内容 
	    controller: [ "$scope", function ($scope, $element, $attrs, $transclude) { …  }], 
	    link: function (scope, element, attrs, controller) {…} 
	  } 
	});
	*/
	/*
	如果不使用^前缀，指令只会在自身的元素上查找控制器。指令定义只会查找定义在指令作当前用域中的ng-model=""
	如果使用?前缀,在当前指令中没有找到所需要的控制器，会将null作为传给link函数的第四个参数。
	如果添加了^前缀，指令会在上游的指令链中查找require参数所指定的控制器。
	如果添加了?^ 将前面两个选项的行为组合起来，我们可选择地加载需要的指令并在父指令链中进行查找
	如果没有任何前缀，指令将会在自身所提供的控制器中进行查找，如果没有找到任何控制器（或具有指定名字的指令）就抛出一个错误
	
	scope参数的作用是，隔离指令与所在控制器间的作用域、隔离指令与指令间的作用域。
	scope参数是可选的，默认值为false，可选true、对象{}；
	false：共享父域
	true：继承父域，且新建独立作用域
	对象{}：不继承父域，且新建独立作用域
	*/


	//日期控件语言包初始化
	require(['bootstrapDatepicker'], function (bootstrapDatepicker) {
	    
	    /*
	    $.fn.datepicker.dates['en'] = {
	    	    days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
	    	    daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
	    	    daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
	    	    months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
	    	    monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
	    	    today: "Today",
	    	    clear: "Clear",
	    	    format: "mm/dd/yyyy",
	    	    titleFormat: "MM yyyy",  Leverages same syntax as 'format' 
	    	    weekStart: 0
	    	};
	    */
		
		$.fn.datepicker.dates["zh-CN"]={days:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],daysShort:["周日","周一","周二","周三","周四","周五","周六"],daysMin:["日","一","二","三","四","五","六"],months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],monthsShort:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],today:"今日",clear:"清除",format:"yyyy年mm月dd日",titleFormat:"yyyy年mm月",weekStart:1};
//		$('.datepicker').datepicker({
//		});
	});
	
//	require(['bootstrapDatetimePicker'], function (bootstrapDatetimepicker) {
//		
//	});

//	console.log('directives-->',directives);

	//订单尾部的物料详细信息
	directives.directive('bottomTab',['systemService',function(systemService){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//			  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/bottomTab.html';
			  },
			  replace: false,
			  scope: {
				  sourceData: '=',        
			      itemClick: "&",            
			      fromClick: "&",            
			      toClick: "&"
			  },
			 controller:['$scope', function($scope){
				 this.name='我是指令中的控制器！';
//				 console.log('$scope.sourceData.rows-->',$scope.sourceData.rows);

				 $scope.triggerBatchNoClick = function($event){
					var options = {};
					
					options.recordState = 'none';
					options.id = $scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].enterpriseNo.value;
					options.itemID = $scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].itemID.value;
					var modalInstance = systemService.openBatchNoDialog(options);
					
			        //模态窗口关闭之后执行的事件
			        modalInstance.result.then(function (event) {  
			             //成功关闭窗口
			         	var simpleRow = event.data[0];
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].batchNo.value = simpleRow.batchNo;
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].batchDescribe.value = simpleRow.batchDescribe;

			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].produceDate.value = simpleRow.produceDate;
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].validDate.value = simpleRow.validDate;
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].checkoutAgainDate.value = simpleRow.checkoutAgainDate;

			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].brand.value = simpleRow.brand;
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].brandLabel.value = simpleRow.brandLabel;
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].placeOrigin.value = simpleRow.placeOrigin;
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].manufacturer.value = simpleRow.manufacturer;

			        }, function (reason) {  
			            console.info('Modal dismissed at: ' + new Date());  
			        });  
				 };

				 
				 $scope.triggerBatchNoDisabled = function(){
					 if($scope.sourceData.currentIndex!=null){
						 if($scope.sourceData.rows[$scope.sourceData.currentIndex].batchNo.value=='********************'){
							 return true;
						 }else{
							 return $scope.sourceData.readonly();
						 }
					 }else{
						 return true;
					 }
				 };
				 
				 
				 $scope.triggerStoreNoClick = function($event){
					var options = {};
					
					options.recordState = 'none';
					options.id = $scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].enterpriseNo.value;
					options.itemID = $scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].itemID.value;
					options.batchNo = $scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].batchNo.value;

					var modalInstance = systemService.openStoreNoDialog(options);
					
			        //模态窗口关闭之后执行的事件
			        modalInstance.result.then(function (event) {  
			             //成功关闭窗口
						var returnData = event.data;
			        	//首先打包成逗号分隔的字符串，然后再赋值。
		             	var storeNoArray = new Array();

				    	for ( var i = 0; i < returnData.length; i++) {
				    		var simpleRow = returnData[i];
				    		console.log('simpleRow.storeNo-->',simpleRow.storeNo);
				    		storeNoArray.push(simpleRow.storeNo);
				    	}
		             	var storeNo = null;
		             	
		             	if(storeNoArray.length>0){
		             		storeNo = storeNoArray.join(",");
		             	}
			        	$scope.sourceData.rows[$scope.sourceData.getCurrentIndex()].storeNo.value = storeNo;
			        	

			        }, function (reason) {  
			            console.info('Modal dismissed at: ' + new Date());  
			        });  
				 };
					 
				 $scope.triggerStoreNoDisabled = function(){
					 if($scope.sourceData.currentIndex!=null){
						 if($scope.sourceData.rows[$scope.sourceData.currentIndex].storeNo.value=='********************'){
							 return true;
						 }else{
							 return $scope.sourceData.readonly();
						 }
					 }else{
						 return true;
					 }
				 };


			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
			 
		 };
	 }])
	 
	//制单信息
	directives.directive('cetInfo',function(){
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/cetInfo.html';
			  },
			  replace: false,
			  scope: {
				  targetData: '='
			  },
			 controller:['$scope', function($scope){
			 }],
			 link:function (scope, element, attrs, controller){
			 }
		 };
	 })
	 
	//单据审签类型
	directives.directive('flowType',function(){
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/flowType.html';
			  },
			  replace: false,
			  scope: {
				  targetData: '=',
				  targetValue: '@',
				  rowIndex: '=',
				  forceDisabled: '@'
			  },
			 controller:['$scope', function($scope){
			    //审签方式
			    $scope.dataFlowType = [
			                        {value:0,label:'0:不送审自动审核'}
			                        ,{value:1,label:'1:非工作流审签'}
			                        ,{value:2,label:'2:自由工作流审签'}
//			                        ,{value:3,label:'3:工作流审签'}
			                        ];

			 }],
			 link:function (scope, element, attrs, controller){
//				 console.log('scope.forceDisabled-->',scope.forceDisabled);
//				 if(scope.forceDisabled==true){
//					 console.log(true);
//				 }
			 }
		 };
	 })

	 //前一行，后一行
	directives.directive('rowInation',function(){
		 
		 return {
			  restrict: 'EA',
//			  templateUrl: 'js/_directives/rowInation.html',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/rowInation.html';
			  },
			  replace: true,
			  scope: {
				  data: '=',
			      firstText: '@',
			      previousText: '@',
			      nextText: '@',
			      lastText: '@',
			      firstShow: '@',
			      previousShow: '@',
			      nextShow: '@',
			      lastShow: '@'
			  },
			 controller:['$scope', function($scope){
			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
		 };
	 })

	 //单据办理（审核、批准）
	directives.directive('billHandleConfirm',['$rootScope','systemService', 'OssEndpoint'
		,function($rootScope, systemService, OssEndpoint){
		 
		 return {
			  restrict: 'EA',
//			  templateUrl: 'js/_directives/rowInation.html',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/billHandleConfirm.html';
			  },
			  replace: true,
			  scope: {
				  data: '=',
			  },
			 controller:['$scope', function($scope){
				 //console.log('billHandleConfirm.path',$rootScope.path);
				 
				 $scope.triggerConfirmClick = function(event){
					// 提交单据
					var data = new Object();
					data.bizData = $scope.data;//Model.dataMaster;
					data.url = $rootScope.path + '/confirm';
					var response = systemService.operateBill(data);
				};
				
				$scope.triggerAgreeItClick = function(event){
					// 审核单据
					var data = new Object();
					data.bizData = $scope.data;//Model.dataMaster;
					data.url = $rootScope.path + '/agreeIt';
					systemService.operateBill(data);
				};
				
				 
			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
		 };
	 }])

	 //单据办理（撤销审核、撤销批准）
	directives.directive('billHandleActive',['$rootScope','systemService', 'OssEndpoint'
		,function($rootScope, systemService, OssEndpoint){
		
		 return {
			  restrict: 'EA',
//			  templateUrl: 'js/_directives/rowInation.html',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/billHandleActive.html';
			  },
			  replace: true,
			  scope: {
				  data: '=',
			  },
			 controller:['$scope', function($scope){
				 //console.log('billHandleActive.path',$rootScope.path);
				 
				$scope.triggerActiveClick = function(event){
					// 撤销提交
					var data = new Object();
					data.bizData =  $scope.data;//Model.dataMaster;
					data.url = $rootScope.path + '/active';
					systemService.operateBill(data);
				};
				
				$scope.triggerUnAgreeClick = function(event){
					// 撤销审核
					var data = new Object();
					data.bizData =  $scope.data;//Model.dataMaster;
					data.url = $rootScope.path + '/unAgree';
					systemService.operateBill(data);
				};
				 
			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
		 };
	 }])

	 //单据办理（撤销审核、撤销批准）
	directives.directive('billHandleClose',['$rootScope','systemService', 'OssEndpoint'
		,function($rootScope, systemService, OssEndpoint){
		
		 return {
			  restrict: 'EA',
//			  templateUrl: 'js/_directives/rowInation.html',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/billHandleClose.html';
			  },
			  replace: true,
			  scope: {
				  data: '=',
			  },
			 controller:['$scope', function($scope){
				 //console.log('billHandleClose.path',$rootScope.path);

				$scope.triggerCloseClick = function(event){
					// 关闭单据
					var data = new Object();
					data.bizData = $scope.data;//Model.dataMaster;
					data.url = $rootScope.path + '/close';
					systemService.operateBill(data);
				};
				$scope.triggerOpenClick = function(event){
					// 撤销审核
					var data = new Object();
					data.bizData = $scope.data;//Model.dataMaster;
					data.url =  $rootScope.path + '/open';
					systemService.operateBill(data);
				};
				 
			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
		 };
	 }])

	 /*
	 directives.directive('onRenderAfter',[function(){  
        return {  
            restrict:'A',  
            link:function ($scope, element, attrs, controller) {  
                var fun = $scope.$eval(attrs.onRenderAfter);//计算表达式的值 
                console.log('attrs.onRenderAfter-->',attrs.onRenderAfter);
                console.log('attrs.onRenderAfter.fun-->',fun);
                if(fun && typeof(fun)=='function'){  
                    fun();  
                }  
            }  
        };  
    }]);  
	*/
	
	 // 表格过滤器 
	directives.directive('gridFilter', [ '$compile', function ($compile) {
        return {
    		require: '?ngModel',
            restrict: 'EA',
            controller: [ "$scope", function ($scope, $element, $attrs, $transclude) {
//            	console.log('gridFilter.controller-->',$scope);
            }],
            template:'<input type="text" class="form-control"/>',
//            templateUrl: 'js/_directives/gridFilter.html',
			replace: true,
            scope: {
                'filterData': '='
                ,'filterRelation': '@'
                ,'autoRefresh': '@'
                ,'onRenderAfter': '&'
            },
            link: function (scope, element, attrs, ngModel) {
//            	console.log('gridFilter.link.start-->',scope);
//	           	console.log('scope.filterData-->',scope.filterData);
//	           	console.log('scope.filterRelation-->',scope.filterRelation);
//	           	console.log('scope.autoRefresh-->',scope.autoRefresh);
//	           	console.log('element-->',element);
//	           	console.log('attrs-->',attrs.xid);
           	           	
	           	
            	var relation = scope.filterRelation;
            	var index = relation.indexOf(".");
            	if(index!=-1){
            		//存在表明
            		relation = relation.substring(index+1,relation.length);
//	                console.log('relation-->',relation);
            	}
            	var colType = scope.filterData.getColumnType(relation);
//	            	console.log('colType-->',colType);
            	
    			if(colType=='Date'){
                    $(element).datepicker({
                        format: "yyyy-mm-dd",
                        clearBtn: true,
                        language: "zh-CN",
                        orientation: scope.orientation,//"top auto",
                        autoclose: true,
                        todayHighlight: true
                    });
    			}
            	
//        		console.log('$(element[0]).val()-->',value);
//            	ngModel.$setViewValue(value);
 
//    			scope.$watch("ngModel.$viewValue", function() {
    			$(element).on("change", function() {
            		var value = $(element[0]).val();
//    				console.log('gridFilter.change-->',value);
//            		var value = '';
//                	if(ngModel!=null){
//                		value = ngModel.$viewValue;
//                	}
            		
            		if(value!=''){
            			if(colType=='Date'){
                			value = scope.filterRelation + "='" + value + "'";
            			}
            			if(colType=='String'){
                			value = scope.filterRelation + "='" + value + "'";
            			}
            			if(colType=='Decimal' || colType=='Integer'){
            				//判断value是否是数字
            				if(isNaN(value)){
            					//不是数字
            					alert('不是数字，请输入数字！');
            					return;
            				}
                			value = scope.filterRelation + "=" + value + "";
            			}
                		//设置过滤条件
                		scope.filterData.setFilter(attrs.xid,value);
            		}else{
                		//删除过滤条件
                		scope.filterData.deleteFilter(attrs.xid);
            		}
            		
//	            	console.log('filterData.getFilter(attrs.xid)-->',scope.filterData.getFilter(attrs.xid));
            		/*
	            	console.log('scope.autoRefresh-->',scope.autoRefresh);
	            	if(scope.autoRefresh=='true'){
		            	console.log('scope.autoRefresh-->','true');
	            		scope.filterData.refreshData();
	            	}
	            	if(scope.autoRefresh=='false'){
		            	console.log('scope.autoRefresh-->','false');
	            	}
	            	*/
            	});
            	
//	            console.log('ngModel-->',ngModel);
	            
            	if(ngModel!=null){
            		ngModel.$render = function() {
//			           	console.log('gridFilter.ngModel.$render-->开始');
//		            	element.val(ngModel.$viewValue || '');
			           	$(element[0]).val(ngModel.$viewValue || '');
//				        $compile($(element).contents())(scope);
			           	
			           	$(element).change();
			           	//触发render之后的事件
			           	/*
			           	var fun = scope.$eval(attrs.onRenderAfter);//计算表达式的值 
		                console.log('attrs.onRenderAfter-->',attrs.onRenderAfter);
		                if(fun && typeof(fun)=='function'){  
		                    fun();  
		                }else{
		                	console.log('fun不是一个函数！');
		                }
		                */
		                
			           	//向父亲提交渲染完成事件
			    		scope.$emit('gridFilter',attrs.xid);

			    		
			           	var fun = scope.onRenderAfter;//渲染之后调用 
//		                console.log('attrs.onRenderAfter-->',attrs.onRenderAfter);
		                if(fun && typeof(fun)=='function'){  
		                    fun();  
		                }
//		                else{
//		                	console.log('fun不是一个函数！');
//		                }
//			           	console.log('gridFilter.ngModel.$render-->结束');
	            	}
	            };
//            	console.log('gridFilter.link.end-->',scope);
            }
        };
    }])
	// 日期范围过滤器 
	directives.directive('rangeFilter', function () {
        return {
    		require: '?ngModel',
            restrict: 'EA',
            controller: '',
            templateUrl: 'js/_directives/rangeFilter.html',
			replace: true,
            scope: {
                'filterData': '='
                ,'filterRelation': '@'
                ,'autoRefresh': '@'
            },
            link: function (scope, element, attrs, ngModel) {
//            	console.log('scope.filterData-->',scope.filterData);
//            	console.log('scope.filterRelation-->',scope.filterRelation);
//            	console.log('scope.autoRefresh-->',scope.autoRefresh);
//            	console.log('attrs-->',attrs.xid);
            	
            	var relation = scope.filterRelation;
            	var index = relation.indexOf(".");
            	if(index!=-1){
            		//存在表明
            		relation = relation.substring(index+1,relation.length);
//                	console.log('relation-->',relation);
            	}
            	var colType = scope.filterData.getColumnType(relation);
//            	console.log('colType-->',colType);
            	
    			if(colType=='Date'){
                    $(element).datepicker({
                        format: "yyyy-mm-dd",
                        clearBtn: true,
                        language: "zh-CN",
                        orientation: scope.orientation,//"top auto",
                        autoclose: true,
                        todayHighlight: true
                    });
    			}
            	
//            	console.log('scope.ngModel-->',scope.ngModel);
//        		console.log('element-->',element);
//        		console.log('$(element)-->',$(element));
        		var domStart = element.find('.inputStart');
        		var domEnd = element.find('.inputEnd');
//        		console.log('domStart-->',domStart);
        		
            	$(domStart).on("change", function() {
            		var value1 = $(this).val();
            		var value2 = element.find('.inputEnd').val();
        			add(value1,value2);
            	});
        		
            	$(domEnd).on("change", function() {
            		var value1 = element.find('.inputStart').val();
            		var value2 = $(this).val();
        			add(value1,value2);
            	});
            	
            	function add(value1,value2){
            		var value = '';
//            		console.log('value1-->',value1);
//            		console.log('value2-->',value2);
//            		console.log('value-->',value);
            		
        			if(colType=='String' || colType=='Date'){
        				if(value1!=''){
                			value1 = scope.filterRelation + ">='" + value1 + "'";
        				}
        				if(value2!=''){
                			value2 = scope.filterRelation + "<='" + value2 + "'";
        				}
        			}
        			if(colType=='Decimal' || colType=='Integer'){
        				//判断value是否是数字
        				if(isNaN(value1) || isNaN(value2)){
        					//不是数字
        					alert('不是数字，请输入数字！');
        					return;
        				}
        				if(value1!=''){
                			value1 = scope.filterRelation + ">=" + value1 + "";
        				}
        				if(value2!=''){
                			value2 = scope.filterRelation + "<=" + value2 + "";
        				}
        			}
        			
        			if(value1!='' && value2!=''){
//        				value = "(" + value1 + " AND " + value2 + ")";
        				value = value1 + " AND " + value2;
        			}else if(value1!=''){
        				value = value1;
        			}else if(value2!=''){
        				value = value2
        			}else{
        				value = '';
        			}
        			
//            		console.log('value1-->',value1);
//            		console.log('value2-->',value2);
//            		console.log('value-->',value);

        			if(value!=''){
                		//设置过滤条件
                		scope.filterData.setFilter(attrs.xid,value);
            		}else{
                		//删除过滤条件
                		scope.filterData.deleteFilter(attrs.xid);
            		}
        			
//            		console.log('filter-->',scope.filterData.getFilter(attrs.xid));
            		
            	};
            	
            	
            }
        };
    })

	directives.directive('itemProcess',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//			  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
//				  selectData: '=',
//				  selectLabel: '@',
//				  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			  /*
			 controller:['$scope','processService', function($scope,processService){
					var response = processService.query();
					response.success(function(data, status, headers, config) {
						$scope.selectData = data;
					});
					response.error(function(data, status, headers, config) {
						alert( "Exception details: " + JSON.stringify({data: data}));
					});
				*/	

			  controller:['$scope', function($scope){
				 $scope.selectData = 
					 [
					 {"process":"P","processLabel":"P.采购件"}
					 ,{"process":"M","processLabel":"M.自制件"}
					 ,{"process":"E","processLabel":"E.委外件"}
					 ,{"process":"V","processLabel":"V.虚拟件"}
//					 ,{"process":"C","processLabel":"C.配置件"}
					 ,{"process":"S","processLabel":"S.服务"}
//					 ,{"process":"R","processLabel":"R.维修件"}
//					 ,{"process":"Z","processLabel":"Z.资产类"}
					 ];				 
				 $scope.selectLabel = 'processLabel';
				 $scope.selectValue = 'process';

				 $scope.itemClick = function(item, $event){
					 //赋值
					 /*
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					
					 //多选时可以使用此事件
//					 $event.stopPropagation();
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
			 
		 };
	 })

	directives.directive('qualityType',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
//					  selectData: '=',
//					  selectLabel: '@',
//					  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			  /*
			 controller:['$scope','qualityTypeService', function($scope,qualityTypeService){
					var response = qualityTypeService.query();
					response.success(function(data, status, headers, config) {
						$scope.selectData = data;
					});
					response.error(function(data, status, headers, config) {
						alert( "Exception details: " + JSON.stringify({data: data}));
					});
					*/
			controller:['$scope', function($scope){
				$scope.selectData = [
					  {"qualityType":0,"qualityTypeLabel":"0:免检"}
					  ,{"qualityType":1,"qualityTypeLabel":"1:抽检（减量）"}
					  ,{"qualityType":2,"qualityTypeLabel":"2:抽检（正常）"}
					  ,{"qualityType":3,"qualityTypeLabel":"3:抽检（加严）"}
					  ,{"qualityType":4,"qualityTypeLabel":"4:全检"}
					  ]
				
				 $scope.selectLabel = 'qualityTypeLabel';
				 $scope.selectValue = 'qualityType';

				 $scope.itemClick = function(item, $event){
					 //赋值
					 /*
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					
					 //多选时可以使用此事件
//						 $event.stopPropagation();
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
			 
		 };
	 })

	directives.directive('qualityStatus',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
//					  selectData: '=',
//					  selectLabel: '@',
//					  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			  /*
			 controller:['$scope','qualityStatusService', function($scope,qualityStatusService){
					var response = qualityStatusService.query();
					response.success(function(data, status, headers, config) {
						$scope.selectData = data;
					});
					response.error(function(data, status, headers, config) {
						alert( "Exception details: " + JSON.stringify({data: data}));
					});
			   */
			controller:['$scope', function($scope){
				$scope.selectData = [
//						{"qualityStatus":0,"qualityStatusLabel":"0:免检"},
//						{"qualityStatus":1,"qualityStatusLabel":"1:待验"},
						{"qualityStatus":2,"qualityStatusLabel":"2:合格"},
						{"qualityStatus":3,"qualityStatusLabel":"3:不良"},
						{"qualityStatus":4,"qualityStatusLabel":"4:特采"}
					];
				
				$scope.selectLabel = 'qualityStatusLabel';
				$scope.selectValue = 'qualityStatus';

				$scope.itemClick = function(item, $event){
					 //赋值
					 /*
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					
					 //多选时可以使用此事件
//						 $event.stopPropagation();
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
			 
		 };
	 })

	directives.directive('selectWithLabel',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
				  selectData: '=',
				  selectLabel: '@',
				  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',/*dropup;dropdown*/
				  horizon: '@',/*left;right*/
				  forceDisabled: '&',
				  itemCheckedToggle: '&',
				  itemClicked: '&',
				  onSelected: '&'
			  },
			 controller:['$scope', function($scope){
				 this.name='我是指令中的控制器！';
				 $scope.itemClick = function(item, $event){
					 //赋值
					 /*
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 //console.log('item-->>',item);
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 //多选时可以使用此事件
					 //$event.stopPropagation();
					 $scope.onSelected({item:item});
					 
					 var event = {
							 param1:1,
							 param2:'test2',
							 item:item
					 }
					 $scope.itemClicked({event:event});
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
//					 scope.rowIndex = scope.targetData.currentIndex;
//					console.log('scope.forceDisabled-->',scope.forceDisabled);
			 }
			 
		 };
	 })

	directives.directive('invoiceCategory',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//					  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
//						  selectData: '=',
//						  selectLabel: '@',
//						  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			 controller:['$scope', function($scope){
				 this.name='我是指令中的控制器！';
				 $scope.selectData = [
				                        {value:'A',label:'A.增值税专用发票'}
				                        ,{value:'B',label:'B.增值税普通发票'}
				                        ,{value:'C',label:'C.服务性发票'}
				                        ,{value:'D',label:'D.其他'}
				                        ];
				 $scope.selectLabel = 'label';
				 $scope.selectValue = 'value';

				 $scope.itemClick = function(item, $event){
					 //赋值
					 /*
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 //多选时可以使用此事件
//					 $event.stopPropagation();
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
			 
		 };
	 })

	directives.directive('settleCategory' ,function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
//					 selectData: '=',
//					 selectLabel: '@',
//					 selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  
				  capitalID: '@',
				  capitalNo: '@',
				  capitalName: '@',
				  capitalFullName: '@',
				  
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			 controller:['$rootScope', '$scope', function($rootScope, $scope){
				 this.name='我是指令中的控制器！';
				 //console.log('this.name-->',this.name);
				 if($scope.rowIndex==undefined){
					 $scope.rowIndex = $scope.targetData.currentIndex;
				 }
//					 $scope.selectData = [
//					                        {value:'1',label:'1.支票'}
//					                        ,{value:'2',label:'2.汇票'}
//					                        ,{value:'3',label:'3.现金'}
//					                        ,{value:'4',label:'4.支付宝'}
//					                        ,{value:'5',label:'5.网上银行'}
//					                        ,{value:'8',label:'8.货到付款'}
//					                        ,{value:'9',label:'9.其他'}
//					                        ];
				/*
				var response = settleInfoOrgService.getSettleCategorys();
				response.success(function(data, status, headers, config) {
					//console.log('data-->',data);
					$scope.selectData = data;
				});
				response.error(function(data, status, headers, config) {
					alert( "Exception details: " + JSON.stringify({data: data}));
				});
				*/
				$.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getProjectName() + "/baseinfo/settleCategory/getList",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
						//console.log('settleCategory.data-->',data);
						if(data.code==0){
							$scope.selectData = data.data;
						}else{
							alert('结算方式数据加载失败！');
						}
		            }
		        });
				 
				$scope.selectLabel = 'settleName';
				$scope.selectValue = 'settleCode';

				$scope.itemClick = function(item, $event){
					//赋值
					$scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					$scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					/*
					$scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					$scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					*/
					//console.log('$scope.capitalID-->',$scope.capitalID);
					if($scope.capitalID){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalID].value = item.capitalID;
					}
					if($scope.capitalNo){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalNo].value = item.capitalNo;
					}
					if($scope.capitalName){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalName].value = item.capitalName;
					}
					if($scope.capitalFullName){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalFullName].value = item.capitalFullName;
					}
					
					//多选时可以使用此事件
//					$event.stopPropagation();
				};
				 

			 }],
			 link:function (scope, element, attrs, controller){
				 //console.log('controller-->',controller);
				
			 }
			 
		 };
	 })

	directives.directive('settleCategoryTile' ,function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithTile.html';
			  },
			  replace: false,
			  scope: {
//					  selectData: '=',
//					  selectLabel: '@',
//					  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  
				  capitalID: '@',
				  capitalNo: '@',
				  capitalName: '@',
				  capitalFullName: '@',
				  
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			 controller:['$rootScope', '$scope', function($rootScope,$scope){
				 this.name='我是指令中的控制器！';
				 //初始化函数
		         $scope.viewInit = function(){
					 //console.log('$scope.targetData.currentIndex-->',$scope.targetData.currentIndex);
		        	 if($scope.targetData.currentIndex!=null){
						for(var i=0;i<$scope.selectData.length;i++){
							if($scope.selectData[i][$scope.selectValue]==$scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value){
								$scope.selectData[i].rowState = 'Y';
							}else{
								$scope.selectData[i].rowState = null;
							}
						}
		        	 }
		        	 
		         };
		         /*
				var response = settleInfoOrgService.getSettleCategorys();
				response.success(function(data, status, headers, config) {
					//console.log('data-->',data);
					$scope.selectData = data;
					//完成初始化赋值
					$scope.viewInit()
					
					//启动监视程序 
					$scope.$watch('targetData.currentIndex',function(newValue,oldValue,scope){
//						console.log('newValue-->',newValue);
						$scope.viewInit();
//						console.log('data当前索引改变！');
					},false);
					
				});
				response.error(function(data, status, headers, config) {
					alert( "Exception details: " + JSON.stringify({data: data}));
				});
				*/
				$.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getProjectName() + "/baseinfo/settleCategory/getList",
//			        data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
						//console.log('settleCategoryTile.data-->',data);
						if(data.code==0){
							$scope.selectData = data.data;
							//完成初始化赋值
							$scope.viewInit()
							
							//启动监视程序 
							$scope.$watch('targetData.currentIndex',function(newValue,oldValue,scope){
//								console.log('newValue-->',newValue);
								$scope.viewInit();
//								console.log('data当前索引改变！');
							},false);
						}else{
							alert('结算方式数据加载失败！');
						}
		            }
		        });

				 
				$scope.selectLabel = 'settleName';
				$scope.selectValue = 'settleCode';

				$scope.itemClick = function(item, $event){
//					console.log('row-->',item);
					for(var i=0;i<$scope.selectData.length;i++){
						$scope.selectData[i].rowState = null;
					}
					item.rowState = 'Y';
					//赋值
					$scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					$scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					/*
					$scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					$scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					*/
					//console.log('$scope.capitalID-->',$scope.capitalID);
					if($scope.capitalID){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalID].value = item.capitalID;
					}
					if($scope.capitalNo){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalNo].value = item.capitalNo;
					}
					if($scope.capitalName){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalName].value = item.capitalName;
					}
					if($scope.capitalFullName){
						$scope.targetData.rows[$scope.targetData.currentIndex][$scope.capitalFullName].value = item.capitalFullName;
					}
					
					//多选时可以使用此事件
//					$event.stopPropagation();
				};
				 

			 }],
			 link:function (scope, element, attrs, ngModel){
		    	// Specify how UI should be updated
//	            ngModel.$render = function() {
//	            	console.log(ngModel.$viewValue || '');
//	            };
				
			 }
			 
		 };
	})

	directives.directive('taxType',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/selectWithLabel.html';
			  },
			  replace: false,
			  scope: {
//					  selectData: '=',
//					  selectLabel: '@',
//					  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',
				  horizon: '@'
			  },
			  
				 /*
			 controller:['$scope','taxTypeService', function($scope,taxTypeService){
				var response = taxTypeService.query();
				response.success(function(data, status, headers, config) {
					$scope.selectData = data;
				});
				response.error(function(data, status, headers, config) {
					alert( "Exception details: " + JSON.stringify({data: data}));
				});
				*/
				 
			controller:['$scope', function($scope){
				 $scope.selectData = [
					 {"taxType":-1,"taxTypeLabel":"-1.免税"}
					 ,{"taxType":0,"taxTypeLabel":"0.应税外加"}
					 ,{"taxType":1,"taxTypeLabel":"1.应税内含"}
					 ];
				 
				 $scope.selectLabel = 'taxTypeLabel';
				 $scope.selectValue = 'taxType';

				 $scope.itemClick = function(item, $event){
					 //赋值
					 /*
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.targetData.currentIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					 
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = item[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = item[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = item[$scope.selectLabel];
					 */
					
					 //多选时可以使用此事件
//						 $event.stopPropagation();
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
			 
		 };
	 })
	 //状态
	directives.directive('auditStatus',function(){
		
		return {
			restrict: 'E', // E = Element, A = Attribute, C = Class, M = Comment
			template: "<img src=\"images/check.png\" style=\"position:absolute;z-index:99;right:0px;\" ng-show=\"getStatus()\">",
			/*
			templateUrl: function(element, attrs) {
			    return attrs.templateUrl || 'js/_directives/auditStatus.html';
			},
			*/
			replace: false,
			scope: {
			    getStatus: "&",            
			},
			controller:['$scope', function($scope){
	//					this.name='我是指令中的控制器！';
			}],
			link:function (scope, element, attrs, controller){
			
			}
			 
		 };
	 })

	directives.directive('modalSelect',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/modalSelect.html';
			  },
			  replace: false,
			  scope: {
				  selectData: '=',
				  selectLabel: '@',
				  selectValue: '@',
				  targetData: '=',
				  targetLabel: '@',
				  targetValue: '@',
				  rowIndex: '=',
				  valueShow: '@',
				  vertical: '@',/*dropup;dropdown*/
				  horizon: '@',/*left;right*/
				  itemCheckedToggle: '&',
				  onSelected: '&'

			  },
			 controller:['$scope', function($scope){
				 
				 this.name='我是指令中的控制器！';
				 //选择当前项目
				 $scope.itemClick = function(item, $event){
					 $scope.currentItem = item;
					 //多选时可以使用此事件
//						 $event.stopPropagation();
				 };
				 
				 //ok赋值
				 $scope.ok = function(){
					 
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = $scope.currentItem[$scope.selectValue];
					 $scope.targetData.rows[$scope.rowIndex][$scope.targetLabel].value = $scope.currentItem[$scope.selectLabel];
					 /*
					 $scope.targetRow[$scope.targetValue].value = $scope.currentItem[$scope.selectValue];
					 $scope.targetRow[$scope.targetLabel].value = $scope.currentItem[$scope.selectLabel];
					 */
					 
					 $scope.onSelected({item:$scope.currentItem});
					 
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				 //打开对话框
				 scope.triggerButtonClick = function(){
					 /*
					 backdrop	boolean 或 字符串 'static'	true	Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click.
					 keyboard	boolean	true	键盘上的 esc 键被按下时关闭模态框。
					 show	boolean	true	模态框初始化之后就立即显示出来。
					 */
					 var options = {
							 backdrop: 'static'
//								 ,keyboard: true
					 };
					 $(element).find('.modal').modal(options);
				 }
			 }
			 
		 };
	 })
		
	directives.directive('modalEdit',function(){
		 
		 return {
			  restrict: 'EA', // E = Element, A = Attribute, C = Class, M = Comment
//				  template: '<div>hello template</div>',
			  templateUrl: function(element, attrs) {
			      return attrs.templateUrl || 'js/_directives/modalEdit.html';
			  },
			  replace: false,
			  scope: {
				  targetData: '=',
				  targetValue: '@',
				  rowIndex: '='
			  },
			 controller:['$scope', function($scope){
				 
				 this.name='我是指令中的控制器！';
				 
				 //添加
				 $scope.addClick = function(event){
					 if($scope.item==undefined || $scope.item==''){
						 return;
					 };
					 //判断数组中是否已经存在
					 for(var i=0;i<$scope.dataArray.length;i++){
						 if($scope.dataArray[i]==$scope.item){
							 alert('已经存在！');
							 return;
						 }
					 }
					 $scope.dataArray.push($scope.item);
					 
					 //多选时可以使用此事件
//						 event.stopPropagation();
				 };
				 
				 //删除
				 $scope.subClick = function(index,event){
					 $scope.dataArray.splice(index,1);
					 
					 //多选时可以使用此事件
//						 event.stopPropagation();
				 };
				 
				 //ok赋值
				 $scope.ok = function(){
					 if($scope.dataArray.length>0){
						 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = $scope.dataArray.join(',');
					 }else{
						 $scope.targetData.rows[$scope.rowIndex][$scope.targetValue].value = '';
					 }
				 };
				 

			 }],
			 link:function (scope, element, attrs, controller){
				 //打开对话框
				 scope.triggerButtonClick = function(){
//						 console.log('scope.targetData.rows[scope.rowIndex][scope.targetValue]-->',scope.targetData.rows[scope.rowIndex][scope.targetValue]);
					 //判断是否支持序列号管理
					 if(scope.targetData.rows[scope.rowIndex][scope.targetValue].value=='********************'){
						 alert('此物料不支持序列号管理，请在物料档案中启用序列号管理。');
						 return;
					 }
					 
					 if(scope.targetData.rows[scope.rowIndex][scope.targetValue].value!=null && scope.targetData.rows[scope.rowIndex][scope.targetValue].value!=''){
						 scope.dataArray = scope.targetData.rows[scope.rowIndex][scope.targetValue].value.split(',');
					 }else{
						 scope.dataArray = new Array();
					 };
//						 console.log('scope.dataArray-->',scope.dataArray);
					 
					 /*
					 backdrop	boolean 或 字符串 'static'	true	Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click.
					 keyboard	boolean	true	键盘上的 esc 键被按下时关闭模态框。
					 show	boolean	true	模态框初始化之后就立即显示出来。
					 */
					 var options = {
							 backdrop: 'static'
//								 ,keyboard: true
					 };
					 
					 var dlg = $(element).find('.modal');
					 
					 dlg.modal(options);
				 }
			 }
			 
		 };
	 })

	directives.directive('pagInation',function(){
		 
		 return {
			  restrict: 'EA',
			  templateUrl: 'js/_directives/pagInation.html',
			  replace: true,
			  scope: {
				  data: '=',
			      firstText: '@',
			      previousText: '@',
			      nextText: '@',
			      lastText: '@',
//				      firstShow: '@',
//				      previousShow: '@',
//				      nextShow: '@',
//				      lastShow: '@'
			  },
			 controller:['$scope', function($scope){
			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
		 };
	 })

	directives.directive('queryLike',function(){
		 
		 return {
			  restrict: 'EA',
			  templateUrl: 'js/_directives/queryLike.html',
			  replace: true,
			  scope: {
				  data: '=',
			      size: '@',
//				      previousText: '@',
//				      nextText: '@',
//				      lastText: '@',
//				      firstShow: '@',
//				      previousShow: '@',
//				      nextShow: '@',
				  placeHolder: '@'
			  },
			 controller:['$scope', function($scope){
			 }],
			 link:function (scope, element, attrs, controller){
				
			 }
		 };
	 })

	directives.directive("tdInput", ['$compile', function($compile) {
		
		  return { 
			require: '?ngModel',
		    restrict: "A",        // 指令是一个元素 (并非属性) 
		    
		    scope: {              // 设置指令对于的scope 
		      ngModel: '=',
		      name: "@",          // name 值传递 （字符串，单向绑定） 
		      amount: "=",        // amount 引用传递（双向绑定） 
		      iptclick: "&",           // 保存操作 
		      optclick: "&"
		    }, 
//			    scope:true,
//			    template:             // 替换HTML (使用scope中的变量) 
//			      "<input ng-hide='false' ng-model='row.itemNo.value' />",
//			      "<span style='width: 100px;border:1px solid #0000ff;' data-ng-bind='row.itemNo.value'></span>",	    
//			    replace: false,        // 使用模板替换原始标记 
//			    transclude: true,    // 嵌入，不复制原始HTML内容 
//			    controller:'invQTRKSingleCtrl',
//			    controller: [ "$scope", function ($scope, $element, $attrs, $transclude) {
//			    	$transclude(function (clone) {              
//		                var a = angular.element('<a>');
//		                a.attr('href', $attrs.value);
//		                a.text(clone.text());
//		                $element.append(a);
//		            });
//			    	$scope.name='hhhhhhhhhhhhhhhhhhhh';
//			    	$scope.amount=999999999.99;
//			    	$scope.amountChanged=function(){
//			    		if($scope.amount!=999999999.99){
//			    		}
//			    	}
//			    	$scope.save=function(){
//			    	}
//			    }], 
		    
		    link: function (scope, element, attrs, ngModel) {
		    	/*
		    	// Specify how UI should be updated
	            ngModel.$render = function() {
	            	element.val(ngModel.$viewValue || '');
	            };
	            // Listen for change events to enable binding
	            element.on('blur keyup change', function() {
	              scope.$apply(read);
	            });
	            read(); // initialize
	            // Write data to the model
	            function read() {
	              var val = element.val();
	              ngModel.$setViewValue(val);
	            }
	            */
//			    	scope.amount = 0.00000000;
//			    	scope.save();
//			    	var html = element.html();


	           // Write data to the model
	            function read(dom) {
	            	dom.val(ngModel.$viewValue)
		        }
	            function write(dom) {
//		            	console.log('dom-->',dom);
//		            	console.log('dom.val()-->',dom.val());
//		            	console.log('dom[0].type-->',dom[0].type);
//		            	console.log('ngModel-->',ngModel);
	            	var value = dom.val();
	            	if(dom[0].type=='number'){
	            		value = parseFloat(value);
	            	}
	            	ngModel.$setViewValue(value);
	            }
	            function inputCreate(input){
		    		//首先隐藏p
		    		element.find('span').attr('hidden',true);
//			    		element.html('');

		    		//去掉表格的padding
		    		element.css('padding','0px');
	        		//失去焦点事件
	        		input.on('blur',function(event){
	    		    	if(attrs.tdInput!='date'){
//		    	    			($(event.target)).remove();
	    		    		inputRemove(input);
	    		    	}
	        		})
	                // Listen for change events to enable binding
	                input.on('keyup change', function() {
//		                  scope.$apply(write(input));
	                });
		    		input.appendTo(element);
	    			read(input);
		    		//启动日期控件,必须放在read后面执行
		    		if(attrs.tdInput=='date'){
		    			input.datepicker({
		                    format: "yyyy-mm-dd",
		                    clearBtn: true,
		                    language: "zh-CN",
		                    orientation: attrs.orientation,//"bottom auto",//
		                    autoclose: true,
		                    todayHighlight: true
		                }).on('show',function(){
		    			}).on('hide',function(event){
		    				inputRemove(input);
		    			})
		    		}
		    		input.focus();

	            }
	            function inputRemove(input){
	            	//绑定双击事件
			    	element.on('dblclick',dblclick);
		    		//恢复表格的padding
		    		element.css('padding','4px');
		            scope.$apply(write(input));
	            	input.off('blur');
	            	input.off('keyup change');
	            	input.remove();
//			    		element.find('span').attr('hidden',false);
		    		element.find('span').removeAttr('hidden');
//			    		element.html(html);
//			    		$compile(element.contents())(scope);
	            }
	            function inputBtnCreate(input){
		    		//首先隐藏p
		    		element.find('span').attr('hidden',true);

		    		//去掉表格的padding
		    		element.css('padding','0px');
		    		
	         		//按钮点击事件
	        		input.find('button').on('click',function(event){
	   		    		inputBtnRemove(input);
	   		    		scope.iptclick();
	        		})
	                input.find('input').on('keyup change', function() {
	                  scope.$apply(write(input.find('input')));
	                });

	    			//创建元素
	    			input.appendTo(element);
	    			read(input.find('input'));
	    			input.find('input').focus();
	    			
	    			angular.element(window).on('click',function(event){
	    				/*
	    				var cNodes = input[0].childNodes;
	    				for(var i=0;i<cNodes.length;i++){
	    					if(event.target==cNodes[i]){
	    						//鼠标点击在最外层DIV的内部，直接返回
	    						return;
	    					}
	    				}
	    				*/
	    				
						var className = event.target.className;
						//如果类中包含‘cellValue’，则表示是我们的对象
						if(className.indexOf('cellValue')!=-1){
							return;
						}

	   		    		inputBtnRemove(input);
	    			})


	            }
	            function inputBtnRemove(input){
	            	//绑定双击事件
			    	element.on('dblclick',dblclick);
		    		//恢复表格的padding
		    		element.css('padding','4px');
		            scope.$apply(write(input.find('input')));
	        		//按钮点击事件
	            	input.find('button').off('click');
		            input.find('input').off('keyup change');
	            	angular.element(window).off('click');
	            	
	            	//移除元素
	            	input.remove();
	            	
	            	//最后显示p
		    		element.find('span').removeAttr('hidden');
	            }
		    	
	            function dblclick(event){
//		            	event.preventDefault();  //阻止元素的默认事件。
//		            	event.stopPropagation();  //阻止元素冒泡事件
	        		//表级只读
	            	var readonly = element.parent().parent().parent()[0].dataset.readonly;
	        		if(readonly=='true'){
	        			return;
	        		}
	            	//关闭双击事件
	    	    	element.off('dblclick',dblclick);

	        		//双击时打开input
	        		if(attrs.tdInput=='' || attrs.tdInput=='text' || attrs.tdInput=='date'){
	            		//var input = $("<input type='text' style='width:100%;height:100%;border:none;'/>");
	        			var input = $("<input type=\"text\" class=\"form-control input-sm\"/>");
	                	//直接创建input
	    	            inputCreate(input);
	        		}
	            	
	        		if(attrs.tdInput=='number'){
	        			//var input = $("<input type='number' style='width:100%;height:100%;border:none;'/>");
	        			var input = $("<input type=\"number\" class=\"form-control input-sm\"/>");
		        	    //$compile(input)(scope);            	
	                	//直接创建input
	    	            inputCreate(input);
	        		}
	        		
	        		if(attrs.tdInput=='inputbtn'){
	            		var input = $(
	            				"<div class=\"input-group input-group-sm\">"+
	            			      "<input type=\"text\" class=\"form-control cellValue\">"+
	            			      "<span class=\"input-group-btn\">"+
	            			        "<button class=\"btn btn-default cellValue\" type=\"button\"><span class=\"glyphicon glyphicon-th-list\" aria-hidden=\"true\"></span></button>"+
	            			      "</span>"+
	            			    "</div>"
	        				    );
	            		
	            		
	    	            inputBtnCreate(input);
	        		}
	        		if(attrs.tdInput=='outputbtn'){
	        			var input = $(
	            				"<div class=\"input-group input-group-sm\">"+
	          			      "<input readonly type=\"text\" class=\"form-control\">"+
	          			      "<span class=\"input-group-btn\">"+
	          			        "<button class=\"btn btn-default\" type=\"button\"><span class=\"glyphicon glyphicon-th-list\" aria-hidden=\"true\"></span></button>"+
	          			      "</span>"+
	          			    "</div>"
	        				    );
	    	            inputBtnCreate(input);
	        		}

	            }
	 
	            if(attrs.tdInput!='ro'){
	    	    	element.on('dblclick',dblclick);
	            }

//			    	$compile(element.contents())(scope);
		    } 
		  }
		}])
	 
		directives.directive('simpleDatepicker', function () {
	        return {
	    		require: '?ngModel',
	            restrict: 'A',
	            controller: 'simpleDatepickerCtrl',
	            controllerAs: 'dp',
//	            templateUrl: 'app/directive/datepicker.html',
				replace: false,
	            scope: {
	                'orientation': '@'
//	                ,'value': '='
	          	    ,ngModel: '=',
	            },
	            link: function (scope, element, attrs, ngModel) {
	            	//console.log('scope.ngModel-->',scope.ngModel);
	                
	            	$(element).on("changeDate", function() {
//	            		console.log('changeDate');
//	            		console.log('element-->',element);
//	            		console.log('$(element)-->',$(element));
	            		var value = $(element[0]).val();
//	            		console.log('value-->',value);
//	            		$(element[0]).val('1111');
//	            		scope.$apply();
//	                	console.log('scope.ngModel-->',scope.ngModel);
	                	ngModel.$setViewValue(value);
	            	});
	            	
	            	//main.js中已经require并且进行了初始化
					//require(['bootstrapDatepicker'],function (bdp) {
	                ngModel.$render = function() {
//	                	console.log('$render');
//	                	console.log('ngModel-->',ngModel);
//	                	console.log('ngModel.$viewValue-->',ngModel.$viewValue);
//	                	element.val(ngModel.$viewValue || '');
	                    //初始化
	                	
	                	var value = ngModel.$viewValue;
	                	if(value!='undefined'){//undefined代表getCurrentIndex为null，就是当前行为空，不存在当前行
	    	                  
		                      $(element[0]).val(value);
	    	                
//	    	                element.datepicker({
	    	                  $(element).datepicker({
	    	                      format: "yyyy-mm-dd",
//	    	                      startDate: '-3d',
	    	                      clearBtn: true,
	    	                      language: "zh-CN",
	    	                      orientation: scope.orientation,//"top auto",
	    	                      autoclose: true,
	    	                      todayHighlight: true,
//	    	                      todayBtn: true,
//	    	                      daysOfWeekHighlighted: "0,6",
	    	                      defaultViewDate: null//{ year: 1977, month: 04, day: 25 }
	    	                  });
//	  	                	console.log('$(element).datepicker');
	                	}
	                	
	                  
	               };
	            	
	                //这个不适合，会触发多次
	            	/*
	            	$(element).on("change", function() {
	                	console.log('$(element).on("change", function()');
	            	});
	            	*/
	            	
					//});//require结束
	            	
	            }//link结束
	        };//return结束
	    })
	    .controller('simpleDatepickerCtrl', function ($scope) {
        	//console.log('simpleDatepickerCtrl');
	        var self = this;
//	        $('.date').datepicker({
//	            format: "yyyy-mm-dd",
//	            clearBtn: true,
//	            language: "zh-CN",
//	            orientation: "top auto",
//	            autoclose: true,
//	            todayHighlight: true
//	        });
	        
			//设置全局日期控件的参数，如果不设置，控件可以正常运行，使用默认参数
			//////////////////日期控件开始////////////////////////////////////////////////
			/*好像不起作用
			$rootScope.datepicker = {};
//			$rootScope.datepicker.today = function() {  
//		        $rootScope.datepicker.dt = new Date();  
//		    };  
//		    $rootScope.datepicker.today();  
		    
		    $rootScope.datepicker.showWeeks = true;  
		    $rootScope.datepicker.toggleWeeks = function () {  
		        $rootScope.datepicker.showWeeks = ! $rootScope.datepicker.showWeeks;  
		    };  
		    
//		    $rootScope.datepicker.clear = function () {  
//		        $rootScope.datepicker.dt = null;  
//		    };  
		    
		    // Disable weekend selection  
		    $rootScope.datepicker.disabled = function(date, mode) {  
		        return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );  
		    };  
		    $rootScope.datepicker.toggleMin = function() {  
		        $rootScope.datepicker.minDate = ( $rootScope.datepicker.minDate ) ? null : new Date();  
		    };  
//		    $rootScope.datepicker.toggleMin();  
		    $rootScope.datepicker.dateOptions = {  
		        'year-format': "'yy'",  
		        'starting-day': 1	  
		    };  
//		    $rootScope.datepicker.formats = ['yyyy-MM-dd', 'dd-MMMM-yyyy', 'yyyy/MM/dd', 'shortDate'];  
		    $rootScope.datepicker.format = 'yyyy/MM/dd';//$rootScope.datepicker.formats[0];
		    */
			//////////////////日期控件结束////////////////////////////////////////////////
	        
	    })
		
	    //本指令开发还未完成。。。。。。。。。。。。。。。。。。
		directives.directive('simpleDatetimepicker', function () {
	        return {
	    		require: '?ngModel',
	            restrict: 'A',
	            controller: '',
	            controllerAs: '',
//	            templateUrl: 'app/directive/datepicker.html',
				replace: false,
	            scope: {
	                'orientation': '@'
//	                ,'value': '='
	          	    ,ngModel: '=',
	            },
	            link: function (scope, element, attrs, ngModel) {
	            	//console.log('scope.ngModel-->',scope.ngModel);
	                
	            	$(element).on("changeDate", function() {
	            		console.log('changeDate');
	            		console.log('element-->',element);
	            		console.log('$(element)-->',$(element));
	            		var value = $(element[0]).val();
//	            		console.log('value-->',value);
//	            		$(element[0]).val('1111');
//	            		scope.$apply();
//	                	console.log('scope.ngModel-->',scope.ngModel);
	                	ngModel.$setViewValue(value);
	            	});
	            	
	            	//main.js中已经require并且进行了初始化
					//require(['bootstrapDatepicker'],function (bdp) {
	                ngModel.$render = function() {
	                	console.log('$render');
	                	console.log('ngModel-->',ngModel);
	                	console.log('ngModel.$viewValue-->',ngModel.$viewValue);
//	                	element.val(ngModel.$viewValue || '');
	                    //初始化
	                	
	                	var value = ngModel.$viewValue;
	                	if(value!='undefined'){//undefined代表getCurrentIndex为null，就是当前行为空，不存在当前行
	                		value="2012-05-15 21:05";
		                    $(element[0]).val(value);
		                    
	    	                $(element).datetimepicker().on('changeDate', function(ev){
	    	                	console.log('ev-->>',ev);
	    	                	/*
    	                		if (ev.date.valueOf() < date-start-display.valueOf()){
    	                	        //....
    	                	    }
    	                		*/
    	                	});
	    	                
	                	}
	                	
	                  
	               };

	            	
					//});//require结束
	            	
	            }//link结束
	        };//return结束
	    })
	 
	 
	
	
		
		
	//	console.log('三模块通用指令包加载！');
});